package primalgorithms.design;

import java.util.Arrays;

public class _02MinStack {
    //其实完全可以用工具类写的，但是我觉得没那个必要

    private int[] nums;
    private int topIndex;

    public _02MinStack() {
        this.nums = new int[10000];
        this.topIndex = -1;
    }

    public void push(int val) {
        nums[++topIndex] = val;
    }

    public void pop() {
        if (topIndex >= 0){
            nums[topIndex] = 0;
            topIndex--;
        }
    }

    public int top() {
        return nums[topIndex];
    }

    public int getMin() {
        int[] mir = Arrays.copyOf(nums,topIndex+1);
        Arrays.sort(mir);
        return mir[0];
    }
}
